#include <my_header.h>
// 必须总是由客户端先调用sendto发送消息给服务端，
/* Usage:  ./1_client_UDP*/
int main(void){                                  

    char *ip = "192.168.114.128";
    char *port = "8080";

    int socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
    ERROR_CHECK(socket_fd, -1, "socket");

    // 构建struct addr类型
    struct sockaddr_in client_addr;
    client_addr.sin_family = AF_INET;
    client_addr.sin_port = htons(atoi(port));
    client_addr.sin_addr.s_addr = inet_addr(ip);
    
    // 给服务器发送数据
    int res_sendto = sendto(socket_fd, "client", 6, 0, (struct sockaddr*)&client_addr, sizeof(client_addr));
    ERROR_CHECK(res_sendto, -1, "sendto");
    // 接收服务器回复的数据
    char buf[60] = { 0 };
    printf("-------");
    int res_recvfrom = recvfrom(socket_fd, buf, sizeof(buf), 0, NULL, NULL);
    ERROR_CHECK(res_recvfrom, -1, "res_recvfrom");
    printf("server message:%s \n", buf);
    
    close(socket_fd);
    
    return 0;
}


